public class 最大矩形 {

    public static int MAXN = 201;
    public static int[] arr = new int[MAXN];
    public static int[] stack = new int[MAXN];
    public static int r,m,ans;
    public int maximalRectangle(char[][] matrix) {
        ans = 0;
        for (char[] s: matrix) {
            m = s.length;
            for (int i = 0; i < m; i++) {
                if (s[i] == '0') {
                    arr[i] = 0;
                } else {
                    arr[i] += 1;
                }
            }
            compute();
        }
        return r;
    }

    private void compute() {
        r = 0;
        for (int i = 0; i < arr.length; i++) {
            while (r > 0 && arr[i] <= stack[r - 1]) {
                int cur = stack[--r];
                int left = r > 0 ? stack[r - 1] : -1;
                ans = Math.max(ans,(i - left - 1) * arr[cur]);
            }
        }
        while (r > 0 ) {
            int cur = stack[--r];
            int left = r > 0 ? stack[r - 1] : -1;
            ans = Math.max(ans,(arr.length - left - 1) * arr[cur]);
        }
    }
}
